package net.facelib.jni;

import net.facelib.akcore.NativeProductStatus;
import net.facelib.akcore.ProductInitStatus;

/**
 * SDK初始化状态
 * @author guyadong
 *
 */
public enum SdkStatus implements NativeProductStatus{
	SDK_UNINITIALIZED("sdk uninitialized(未初始化)"),
	SDK_INIT_OK(0,"init ok(初始化成功)"),
	SDK_MEMORY_ERROR(-1,"初始化内存分配错误"),
	SDK_SN_ERROR(-401,"serial number error(获取序列号失败)"),
	SDK_LICENSE_DECRYPT_ERROR(-402,"unlocal license decode error(非本地授权文件中的授权码解码失败)"),
	SDK_TIMEOUT(-403,"trial expired(试用授权到期)"),
	SDK_LOCAL_LICENSE_DECRYPT_ERROR(-404,"local license decode error(本地授权文件中的授权码解码失败)"),
	SDK_NO_EXIST_LOCAL_LICENSE(-405,"not exist local license(本地授权文件不存在或者为空或者无权限)"),
	SDK_FAIL_LICENSE_COMPARE(-406,"fail to compare license(授权码与当前设备信息不吻合)"),
	SDK_FAIL_GET_MAC(-407,"fail to compare license(获取不到MAC地址)"),
	SDK_CHANNEL_ID_EXCEED(-408,"channel id exceed (超出最大路数ID)"),
	SDK_LICENSE_PARSE_ERROR(-409,"授权数据解析错误"),
	SDK_UNINITIZLIED_CHANNEL(-501,"uninitizlied channel(当前通道未初始化)"),
	SDK_INPUT_DATA_ERROR(-502,"input data error(输入数据不正确)"),
	SDK_MEMORY_MALLOC(-503,"fail to load model  data caused by memory error(内存分配失败导致模型导入失败)"),
	UNKNOW_ERROR(-2,"Unknown result(未知错误)");
	/** 状态描述信息 */
	public final String msg;
	/** 状态码 */
	public final int error;
	private SdkStatus(String msg){
		this(-1, msg);
	}
	private SdkStatus(int error,String msg){
		this.error = error;
		this.msg = msg;		
	}
	/**
	 * 根据SDK JNI/JNA调用返回的状态码返回{@link SdkStatus}实例
	 * @param code 状态码
	 * @return SDK初始化状态
	 */
	public static SdkStatus jniCode(int code){
		switch(code){
		case 0 :
			return SDK_INIT_OK;
		case -1:
			return SDK_MEMORY_ERROR;
		case -401:
			return SDK_SN_ERROR;
		case -402:
			return SDK_LICENSE_DECRYPT_ERROR;
		case -403:
			return SDK_TIMEOUT;
		case -404:
			return SDK_LOCAL_LICENSE_DECRYPT_ERROR;
		case -405:
			return SDK_NO_EXIST_LOCAL_LICENSE;
		case -406:
			return SDK_FAIL_LICENSE_COMPARE;
		case -407:
			return SDK_FAIL_GET_MAC;
		case -408:
			return SDK_CHANNEL_ID_EXCEED;
		case -409:
			return SDK_LICENSE_PARSE_ERROR;
		case -501:
			return SDK_UNINITIZLIED_CHANNEL;
		case -502:
			return SDK_INPUT_DATA_ERROR;
		default:
			return UNKNOW_ERROR;
		}
	}
	@Override
	public int getCode() {
		return error;
	}
	@Override
	public String getEnumName() {
		return name();
	}
	@Override
	public String getMessage() {
		return msg;
	}

	@Override
	public ProductInitStatus asProductInitStatus() {
		switch(this){
		case SDK_INIT_OK:
			return ProductInitStatus.PRODUCT_INIT_OK;
		case SDK_UNINITIALIZED:
			return ProductInitStatus.PRODUCT_UNINITIALIZED;
		case UNKNOW_ERROR:
			return ProductInitStatus.UNKNOW_ERROR;
		default:
			return ProductInitStatus.PRODUCT_INIT_FAIL;
		}
	}
}
